import { defineStore } from 'pinia'
import { getCategory1, getCategory2, getCategory3 } from '@/apis/goods'
import { category1Int, category2Int, category3Int } from '@/types/goods'
// 分类
export default defineStore('useCategoryStore', () => {
  const c1Arr = ref<category1Int[]>([])
  const c2Arr = ref<category2Int[]>([])
  const c3Arr = ref<category3Int[]>([])
  const c1Id = ref<number | string>()
  const c2Id = ref<number | string>()
  const c3Id = ref<number | string>()

  const getCategory1Fun = async () => {
    const res = await getCategory1()
    c1Arr.value = res.data
  }
  const getCategory2Fun = async (category1Id: number) => {
    const res = await getCategory2(category1Id)
    c2Arr.value = res.data
  }
  const getCategory3Fun = async (category2Id: number) => {
    const res = await getCategory3(category2Id)
    c3Arr.value = res.data
  }
  return {
    c1Arr,
    c2Arr,
    c3Arr,
    c1Id,
    c2Id,
    c3Id,
    getCategory1Fun,
    getCategory2Fun,
    getCategory3Fun
  }
})
